<?php
include("header.php");
?>

<h2>MTMBurner Administration Page</h2>
<hr>
<?php AdminAction(); ?>
<hr>

<table border="1" width="600">
	<tr>
		<td valign="center">
			<form method="POST"><input type="submit" name="submit" value="Reset Questions in DB"></form>
		</td>
		<td>
			<p>This will delete all questions currently defined in the database and repopulate
			it with new entries. This is useful when first setting up the database or when
			one once to change the range of questions covered. By default, this will define
			mutliplication questions ranging from 0x0 to 12x12 (169 combinations).</p>
			
			<p>WARNING: This is likely to cause inconsistencies in the database tables regarding
			specific test results arlready recorded there. The final outcome of the tests
			(number of problems, how many correct, etc..) will remain intact, but specific details
			on which questions were answered correctly may become corrupt. This could lead to 
			new tests not being correctly tailored to focus on the questions the student has been
			having trouble with.</p>
		</td>
	</tr>
	<tr>
		<td valign="center">
			<form method="POST"><input type="submit" name="submit" value="Delete All Questions in DB"></form>
		</td>
		<td>
			<p>This will delete all questions currently defined in the database. This will leave
			the database in a crippled state such that new tests will not be available and existing
			results on specific answers to previous tests will be corrupted. This may be useful
			if you want to populate the database with custom questions though.</p>
		</td>
	</tr>
</table>


<?php
include("footer.php");

//------------------------
// AdminAction
//------------------------
function AdminAction()
{
	global $_REQUEST;

	$cmd = $_REQUEST["submit"];
	if($cmd == "")return;
	
	print "<i><b><u>$cmd:</u></b></i><br>\n";
	
	if($cmd == "Reset Questions in DB"){
		ConfirmResetQuestions();
	}else if($cmd == "Yes, reset all the questions"){
		ClearQuestionsTable();
		PopulateQuestionsTable();
	}else if($cmd == "Delete All Questions in DB"){
		ConfirmDeleteQuestions();
	}else if($cmd == "Yes, delete all the questions"){
		ClearQuestionsTable();
	}

}

//------------------------
// ConfirmResetQuestions
//------------------------
function ConfirmResetQuestions()
{
	?>
	<i>Are you really sure you want to delete all of the questions currently defined in the database?</i>
	<p><form method="POST"><input type="submit" name="submit" value="Yes, reset all the questions"></form></p>
	<p><form method="POST"><input type="submit" name="submit" value="Cancel resetting questions"></form></p>
	<?php
}

//------------------------
// ConfirmDeleteQuestions
//------------------------
function ConfirmDeleteQuestions()
{
	?>
	<i>Are you really sure you want to delete all of the questions currently defined in the database?</i>
	<p><form method="POST"><input type="submit" name="submit" value="Yes, delete all the questions"></form></p>
	<p><form method="POST"><input type="submit" name="submit" value="Cancel deleting questions"></form></p>
	<?php
}

?>

